<template>
  <div class="">
    <div class="login">
      <div class="title">
        <h3 class="headline">
          <img src="../../assets/images/title2.png" alt="">
        </h3>
        <!--<h3 class="fenght" text="烽火台">-->
          <!--<img src="../../assets/images/fht.png" alt="">-->
        <!--</h3>-->
      </div>
      <div class="login-inner">
      <img src="../../assets/images/logo-radar.png" class="login-radar" alt="">
      <form v-show="isShow">
        <div class="login-new" @keyup.enter="login">
          <div class="user-login">登 录</div>
          <div class="uesr-name">
            <input class="username" type="text" placeholder="请输入用户名" autocomplete="off" v-model="userInfo.username" name="username">
          </div>
          <div class="uesr-name user-psd">
            <input class="password" type="password" placeholder="请输入密码" autocomplete="off" v-model="userInfo.password" name="password">
          </div>
          <div class="remember-psd">
            <div class="zh fl">
              <label class="remember-psd-sle fl">
              <input type="checkbox" v-model="userInfo.remberAccount">记住账户</label>
            </div>
            <div class="mm fr" @click="forPsd">
              <a class="fr">忘记密码?</a>
            </div>
          </div>
          <p v-if="errorMsg" class="error-msg">{{errorMsg}}</p>
          <div class="page-user-login" @click="login">立即登录</div>
        </div>
      </form>
      <form class="login1" v-show="isShow1">
        <div class="login-new">
          <div class="user-login">忘记密码</div>
          <div class="uesr-name">
            <div>忘记密码请联系相关负责人:</div>
            <div class="phone">
              <span>联系人: {{personInCharge.name}}</span>
              <span>电话: {{personInCharge.phone}}</span>
            </div>
          </div>
          <div class="page-user-login" @click="confirm">确&nbsp;&nbsp;&nbsp;&nbsp;定</div>
        </div>
      </form>
      </div>
    </div>
  </div>
</template>
<script>
//  import { login as api } from '../../api' QAZxsw2
export default {
  data() {
    return {
      input: '',
      userInfo: {
        username: '',
        password: '',
        remberAccount: false
      },
      errorMsg: '',
      isShow: true,
      isShow1: false,
      personInCharge:{
        name:"庄玮柠",
        phone:"13864668915"
      }
    }
  },
  watch: {
    errorMsg(val) {
      // let _this = this
      if (val) {
        setTimeout(function() {
          // _this.errorMsg = ''
        }, 3000)
      }
    }
  },
  methods: {
    // 忘记密码
    forPsd() {
      this.isShow1 = true
      this.isShow = false
    },
    // 忘记密码页 确定
    confirm() {
      this.isShow1 = false
      this.isShow = true
    },
    login() {
      if (!this.validate()) {
        return false
      }
      let params = {
        username: this.userInfo.username,
        password: this.userInfo.password
      }
      if (params) {
        let username = {
          username:this.userInfo.username
        }
        sessionStorage.setItem('username', JSON.stringify(username))
      }
      var rtn = this.$store.dispatch('login', params)
      rtn
        .then(rtn => {
          // 记住账户名
          if (this.userInfo.remberAccount) {
            localStorage.setItem('userInfo', JSON.stringify(this.userInfo))
          } else {
            localStorage.removeItem('userInfo')
          }
          this.$router.push({ path: '/' })
        })
        .catch(error => {
          if (+error.errCode < 1) {
            this.errorMsg = error.msg
          }
        })
    },
    validate() {
      if (!this.userInfo.username) {
        this.errorMsg = '请输入用户名'
        return false
      }
      if (!this.userInfo.password) {
        this.errorMsg = '请输入密码'
        return false
      }
      return true
    }
  },
  mounted() {
    let userInfo = JSON.parse(localStorage.getItem('userInfo'))
    sessionStorage.removeItem('username')
    if (userInfo && userInfo.remberAccount) {
      this.userInfo.username = userInfo.username
      this.userInfo.password = userInfo.password
      this.userInfo.remberAccount = userInfo.remberAccount
    } else {
      this.userInfo.username = ''
      this.userInfo.password = ''
      this.userInfo.remberAccount = false
    }
  }
}
</script>
<!--<style lang='scss' src="../../assets/css/login.css" scoped></style>-->
<style lang="scss" scoped>
.error-msg {
  color: #e92322;
  text-align: center;
  position: absolute;
  width: 100%;
  bottom: 75px;
}
body {
  width: 100%;
  height: 100%;
  background: #01112e;
}
.login-inner {
  width: 1200px;
  display: flex;
  padding-top: 200px;
  justify-content: space-around;
  margin: 0 auto;
  height: 100%;
  box-sizing: border-box;
  .login-radar {
    height: 650px;
    margin-top: -70px;
  }
  .login-new {
    width: 352px;
    height: 366px;
    margin-top: 30px;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.16);
  }
}
.headline {
  font-size: 48px;
  font-weight: bold;
  color: #8bc4e6;
  letter-spacing: 10px;
  text-align: center;
}
.login1-pic img {
  margin-top: 100px;
}
.login {
  width: 100%;
  min-width: 1280px;
  height: 100vh;
  min-height: 780px;
  background: url(../../../static/images/login-bg.jpg) no-repeat center;
  background-size: 100% 100%;
  position: relative;
  .title {
    width: 100%;
    position: absolute;
    top: 3vh;
    .fenght {
      text-align: center;
      font-size: 46px;
      margin-top: -16px;
      font-weight: bold;
      color: #06b4da;
      background-image: -webkit-gradient(
        linear,
        0 0,
        0 bottom,
        from(rgba(7, 184, 217, 1)),
        to(rgba(0, 141, 234, 0.7))
      );
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      -webkit-text-stroke: 1px #07d7f7;
    }
  }
  .username,
  .password {
    background: #012e61;
    border: 1px solid #1d5b91;
  }
  .mm a {
    cursor: pointer;
    color: #06b4da;
  }
}
//2018.08.20  忘记密码
.login1 {
  .login-new {
    width: 352px;
    height: 366px;
    margin: 5% auto 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 3px;
  }
  .user-login {
    height: 50px;
    text-align: center;
    line-height: 50px;
    font-size: 18px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0px 2px 0px rgba(0, 0, 0, 0.2);
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(2, 110, 158, 1) 50%,
        rgba(255, 255, 255, 0) 100%
      )
      no-repeat;
    background-position: 0 100%;
    background-size: 100% 2px;
  }
  .uesr-name {
    height: 150px;
    text-align: center;
    div {
      line-height: 45px;
      font-size: 16px;
      color: #fff;
    }
    .phone {
      margin:20px 0 0 35px;
      font-size: 26px;
      font-weight: bold;
      color: #47c9ff;
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      justify-content: space-between;
    }
  }
  .page-user-login {
    margin: 45px auto;
    width: 298px;
    height: 42px;
    margin-top: 20px;
    line-height: 42px;
    text-align: center;
    border-radius: 4px;
    background-image: linear-gradient(-35deg, #ff9500 0%, #ffba00 100%),
      linear-gradient(0deg, #26b9fd 1%, #2069bd 100%);
    border-radius: 24px;
    border: solid 1px #ffaa00;
    font-size: 18px;
    cursor: pointer;
  }
}
</style>



// WEBPACK FOOTER //
// src/view/login/login.vue
